
const TokenKey = 'Jushi-Token'

export function getToken() {
  return localStorage.getItem(TokenKey)
}

export function setToken(data) {
  localStorage.setItem(TokenKey, data.access_token);
  localStorage.setItem('token_now', new Date().getTime());
  localStorage.setItem('token_expire', data.expires_in);
}

export function removeToken() {
  return localStorage.removeItem(TokenKey)
}

export function getAuth() {
  var token = localStorage.getItem(TokenKey)
  if (token) {
    return true;
  } else {
    return false;
  }
}
export function checkAuth() {
  var now = new Date().getTime();
  var oldTime = localStorage.getItem('token_now');
  var expire = localStorage.getItem('token_expire');
  return getAuth() && (now - oldTime < expire);
}